

import excel "Dataset_with_list_questions", sheet("Sheet0") firstrow clear

* remove 134 respondents that did not finish
* For robustness: check demographic differences, and check results with these respondents included
keep if Progress==100

* Rename the numerical answer given to the list question, for reshape
rename Q254 lnFemalePoliticians1_DO
rename Q356 lnMalePoliticians1_DO
rename Q458 lnPoliticians1_DO
rename Q560 lnWomen1_DO
rename Q662 lnMen1_DO
rename Q764 lnFemalePoliticians2_DO
rename Q866 lnMalePoliticians2_DO
rename Q968 lnPoliticians2_DO
rename Q1070 lnWomen2_DO
rename Q1172 lnMen2_DO
rename Q1274 lnFemalePoliticians3_DO
rename Q1376 lnMalePoliticians3_DO
rename Q1478 lnPoliticians3_DO
rename Q1580 lnWomen3_DO
rename Q1682 lnMen3_DO

rename Q153_LastClick  tiFemalePoliticians1_DO
rename Q255_LastClick  tiMalePoliticians1_DO
rename Q357_LastClick  tiPoliticians1_DO
rename Q459_LastClick  tiWomen1_DO
rename Q561_LastClick  tiMen1_DO
rename Q663_LastClick  tiFemalePoliticians2_DO
rename Q765_LastClick  tiMalePoliticians2_DO
rename Q867_LastClick  tiPoliticians2_DO
rename Q969_LastClick  tiWomen2_DO
rename Q1071_LastClick tiMen2_DO
rename Q1173_LastClick tiFemalePoliticians3_DO
rename Q1275_LastClick tiMalePoliticians3_DO
rename Q1377_LastClick tiPoliticians3_DO
rename Q1479_LastClick tiWomen3_DO
rename Q1581_LastClick tiMen3_DO

* delete some variables for overview. Make some others lower case
drop Q*FirstClick Q*LastClick Q*PageSubmit Q*ClickCount // timer variables

* Make data long: 12 (out of 15) lists people have seen below each other
reshape long List ln ti, i(ResponseId) j(listquestion) string
order List ln ti
destring ln, replace		// _N=17,985 (19,995 if incompletes not removed)
drop if List=="" & ln==.	// _N=16,321 (16,519 if incompletes not removed)

* Optional: select subset of respondents
//keep if Q4=="Male"
//keep if Q4=="Female"
//keep if Q10=="Democrat"
//keep if Q10=="Independent"
//keep if Q10=="Republican"

* Make dummies for the traits seen in de lists (in German, English will be merged)
gen t_aktiv			= 0 
gen t_abenteuerlu	= 0 
gen t_herzlich		= 0 
gen t_aggressiv		= 0 
gen t_ambitionier	= 0 
gen t_analytisch	= 0 
gen t_arrogant		= 0 
gen t_künstlerisc	= 0 
gen t_durchsetzun	= 0 
gen t_verbittert	= 0 
gen t_überheblich	= 0 
gen t_fürsorglich	= 0 
gen t_vorsichtig	= 0 
gen t_charismatis	= 0 
gen t_grob			= 0 
gen t_kühl			= 0 
gen t_respekteinf	= 0 
gen t_mitfühlend	= 0 
gen t_ehrgeizig		= 0 
gen t_jammernd		= 0 
gen t_selbstsiche	= 0 
gen t_korrupt		= 0 
gen t_kreativ		= 0 
gen t_zynisch		= 0 
gen t_wagemutig		= 0 
gen t_anständig		= 0 
gen t_betrügerisc	= 0 
gen t_unselbständ	= 0 
gen t_entschlosse	= 0 
gen t_hinterhälti	= 0 
gen t_diktatorisc	= 0 
gen t_unehrlich		= 0 
gen t_dominant		= 0 
gen t_getrieben		= 0 
gen t_gebildet		= 0 
gen t_egoistisch	= 0 
gen t_emotional		= 0 
gen t_ethisch		= 0 
gen t_kleinlich		= 0 
gen t_einfühlsam	= 0 
gen t_tatkräftig	= 0 
gen t_problemlösu	= 0 
gen t_gutmitZahle	= 0 
gen t_gierig		= 0 
gen t_leichtgläub	= 0 
gen t_abgebrüht		= 0 
gen t_fleißig		= 0 
gen t_ehrlich		= 0 
gen t_feindselig	= 0 
gen t_phantasievo	= 0 
gen t_bürgernah		= 0 
gen t_unabhängig	= 0 
gen t_inspirieren	= 0 
gen t_intelligent	= 0 
gen t_intuitiv		= 0 
gen t_sachkundig	= 0 
gen t_führungsper	= 0 
gen t_lügner		= 0 
gen t_logisch		= 0 
gen t_liebevoll		= 0 
gen t_manipulativ	= 0 
gen t_integer		= 0 
gen t_mütterlich	= 0 
gen t_motiviert		= 0 
gen t_nörgelend		= 0 
gen t_objektiv		= 0 
gen t_organisiert	= 0 
gen t_machthungri	= 0 
gen t_mächtig		= 0 
gen t_mathematisc	= 0 
gen t_streitsücht	= 0 
gen t_rational		= 0 
gen t_sorgensichu	= 0 
gen t_robust		= 0 
gen t_intrigant		= 0 
gen t_eigennützig	= 0 
gen t_selbstsücht	= 0 
gen t_sensibel		= 0 
gen t_unterwürfig	= 0 
gen t_schmierig		= 0 
gen t_klug			= 0 
gen t_hinterlisti	= 0 
gen t_rückgratlos	= 0 
gen t_streng		= 0 
gen t_stark			= 0 
gen t_willensstar	= 0 
gen t_aufopfernd	= 0 
gen t_sympathisch	= 0 
gen t_gesprächig	= 0 
gen t_taff			= 0 
gen t_nichtinderl	= 0 
gen t_unemotional	= 0 
gen t_prinzipienl	= 0 
gen t_verklemmt		= 0 
gen t_warmherzig	= 0 
gen t_schwach		= 0 
gen t_gutgebildet	= 0 
gen t_wortgewandt	= 0 
gen t_weinerlich	= 0 

* Fill in for the list questions which trait was seen
local startnumlist 155 257 359 461 563 665 767 869 971 1073 1175 1277 1379 1481 1583
foreach startnum of local startnumlist {
	local num = `startnum'
	local endnum = `startnum' + 98
	local answer = `startnum' + 99
	di `num'
	qui replace t_aktiv 		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_abenteuerlu	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_herzlich		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_aggressiv		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_ambitionier	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_analytisch	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_arrogant		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_künstlerisc	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_durchsetzun	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_verbittert	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_überheblich	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_fürsorglich	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_vorsichtig	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_charismatis	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_grob			= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_kühl			= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_respekteinf	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_mitfühlend	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_ehrgeizig		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_jammernd		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_selbstsiche	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_korrupt		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_kreativ		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_zynisch		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_wagemutig		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_anständig		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_betrügerisc	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_unselbständ	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_entschlosse	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_hinterhälti	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_diktatorisc	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_unehrlich		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_dominant		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_getrieben		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_gebildet		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_egoistisch	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_emotional		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_ethisch		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_kleinlich		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_einfühlsam	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_tatkräftig	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_problemlösu	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_gutmitZahle	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_gierig		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_leichtgläub	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_abgebrüht		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_fleißig		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_ehrlich		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_feindselig	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_phantasievo	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_bürgernah		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_unabhängig	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_inspirieren	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_intelligent	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_intuitiv		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_sachkundig	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_führungsper	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_lügner		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_logisch		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_liebevoll		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_manipulativ	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_integer		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_mütterlich	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_motiviert		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_nörgelend		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_objektiv		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_organisiert	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_machthungri	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_mächtig		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_mathematisc	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_streitsücht	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_rational		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_sorgensichu	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_robust		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_intrigant		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_eigennützig	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_selbstsücht	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_sensibel		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_unterwürfig	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_schmierig		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_klug			= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_hinterlisti	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_rückgratlos	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_streng		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_stark			= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_willensstar	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_aufopfernd	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_sympathisch	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_gesprächig	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_taff			= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_nichtinderl	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_unemotional	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_prinzipienl	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_verklemmt		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_warmherzig	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_schwach		= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_gutgebildet	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_wortgewandt	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
	local num = `num' + 1
	qui replace t_weinerlich	= 1 if regex(List,"Q`num'") & regex(List,"Q`answer'")
}

* Simplify target variables, so that repeated questions about the same can be merged
gen target = listquestion
replace target = regexr(target,"1_DO","")
replace target = regexr(target,"2_DO","")
replace target = regexr(target,"3_DO","")
replace target = "female politicians" if target=="FemalePoliticians"
replace target = "male politicians" if target=="MalePoliticians"
replace target = "men" if target=="Men"
replace target = "women" if target=="Women"
replace target = "politicians" if target=="Politicians"
order target


*** Store percentage per group
gen trait = ""
replace trait="aktiv"		in	1
replace trait="abenteuerlu"	in	2
replace trait="herzlich"	in	3
replace trait="aggressiv"	in	4
replace trait="ambitionier"	in	5
replace trait="analytisch"	in	6
replace trait="arrogant"	in	7
replace trait="künstlerisc"	in	8
replace trait="durchsetzun"	in	9
replace trait="verbittert"	in	10
replace trait="überheblich"	in	11
replace trait="fürsorglich"	in	12
replace trait="vorsichtig"	in	13
replace trait="charismatis"	in	14
replace trait="grob"		in	15
replace trait="kühl"		in	16
replace trait="respekteinf"	in	17
replace trait="mitfühlend"	in	18
replace trait="ehrgeizig"	in	19
replace trait="jammernd"	in	20
replace trait="selbstsiche"	in	21
replace trait="korrupt"		in	22
replace trait="kreativ"		in	23
replace trait="zynisch"		in	24
replace trait="wagemutig"	in	25
replace trait="anständig"	in	26
replace trait="betrügerisc"	in	27
replace trait="unselbständ"	in	28
replace trait="entschlosse"	in	29
replace trait="hinterhälti"	in	30
replace trait="diktatorisc"	in	31
replace trait="unehrlich"	in	32
replace trait="dominant"	in	33
replace trait="getrieben"	in	34
replace trait="gebildet"	in	35
replace trait="egoistisch"	in	36
replace trait="emotional"	in	37
replace trait="ethisch"	in	38
replace trait="kleinlich"	in	39
replace trait="einfühlsam"	in	40
replace trait="tatkräftig"	in	41
replace trait="problemlösu"	in	42
replace trait="gutmitZahle"	in	43
replace trait="gierig"	in	44
replace trait="leichtgläub"	in	45
replace trait="abgebrüht"	in	46
replace trait="fleißig"		in	47
replace trait="ehrlich"		in	48
replace trait="feindselig"	in	49
replace trait="phantasievo"	in	50
replace trait="bürgernah"	in	51
replace trait="unabhängig"	in	52
replace trait="inspirieren"	in	53
replace trait="intelligent"	in	54
replace trait="intuitiv"	in	55
replace trait="sachkundig"	in	56
replace trait="führungsper"	in	57
replace trait="lügner"		in	58
replace trait="logisch"		in	59
replace trait="liebevoll"	in	60
replace trait="manipulativ"	in	61
replace trait="integer"	in	62
replace trait="mütterlich"	in	63
replace trait="motiviert"	in	64
replace trait="nörgelend"	in	65
replace trait="objektiv"	in	66
replace trait="organisiert"	in	67
replace trait="machthungri"	in	68
replace trait="mächtig"		in	69
replace trait="mathematisc"	in	70
replace trait="streitsücht"	in	71
replace trait="rational"	in	72
replace trait="sorgensichu"	in	73
replace trait="robust"		in	74
replace trait="intrigant"	in	75
replace trait="eigennützig"	in	76
replace trait="selbstsücht"	in	77
replace trait="sensibel"	in	78
replace trait="unterwürfig"	in	79
replace trait="schmierig"	in	80
replace trait="klug"		in	81
replace trait="hinterlisti"	in	82
replace trait="rückgratlos"	in	83
replace trait="streng"		in	84
replace trait="stark"		in	85
replace trait="willensstar"	in	86
replace trait="aufopfernd"	in	87
replace trait="sympathisch"	in	88
replace trait="gesprächig"	in	89
replace trait="taff"		in	90
replace trait="nichtinderl"	in	91
replace trait="unemotional"	in	92
replace trait="prinzipienl"	in	93
replace trait="verklemmt"	in	94
replace trait="warmherzig"	in	95
replace trait="schwach"		in	96
replace trait="gutgebildet"	in	97
replace trait="wortgewandt"	in	98
replace trait="weinerlich"	in	99

gen l_malpol_us = . 
gen l_fempol_us = .
gen l_allpol_us = .
gen l_women_us  = .
gen l_men_us    = .

gen llb_malpol_us = . 
gen llb_fempol_us = .
gen llb_allpol_us = .
gen llb_women_us  = .
gen llb_men_us    = .

gen lub_malpol_us = . 
gen lub_fempol_us = .
gen lub_allpol_us = .
gen lub_women_us  = .
gen lub_men_us    = .

gen tarshort = ""
replace tarshort = "malpol" if target=="male politicians"
replace tarshort = "fempol" if target=="female politicians"
replace tarshort = "allpol" if target=="politicians"
replace tarshort = "men" if target=="men"
replace tarshort = "women" if target=="women"


* All trait percentages calculated 
levelsof trait, local(traitlist)
foreach group of newlist malpol fempol allpol men women {
	foreach trait of local traitlist {
		qui reg ln t_`trait' if tarshort=="`group'", vce(cluster StartDate)
		qui lincom t_`trait' + _cons/5
		qui replace l_`group' = r(estimate) if trait=="`trait'"
		qui replace llb_`group' = r(lb) if trait=="`trait'"
		    replace lub_`group' = r(ub) if trait=="`trait'"
	}
}

* Store percentages as dataset
preserve
	keep l_* llb_* lub_* trait 
	drop if trait==""
	save "listpercentages_US.dta", replace
	//save "Subgroup data\listpercentages_US.dta", replace
restore


*** Create a different dataset for the scale results
preserve
	* Step 1: Define traits per scale 
	do "Globals scales.do"

	* Step 2: Count how many traits (0-5) beloning in scale a respondent saw
	* Agentic commmunal
	capture drop d_agentic d_communal d_eagly*
	foreach i in newlist _agentic _communal _eaglyagen _eaglycomp {
		gen d`i' = 0		
		foreach trait of global d`i' {
			replace d`i' = d`i' + 1 if t_`trait'==1
		}
	}
	* Leadership prescriptions
	capture drop d_leaderprepro
	gen d_leaderprepro = 0		
	foreach trait of global d_leaderprepro {
		replace d_leaderprepro = d_leaderprepro + 1 if t_`trait'==1
	}
	* Kinder dimensions
	capture drop dk_*
	foreach i of newlist _com _lea _emp _int {
		gen dk`i' = 0		
		foreach trait of global kinder`i' {
			replace dk`i' = dk`i' + 1 if t_`trait'==1
		}
	}
	* Step 3: Predict separately for each group how many trait the respondent selected, depending on the number of traits in the scale they saw. Use this to reconstruct percentage of respondents that finds the average trait of the scale applicable to the social group.
	* Gender intensified prescriptions & Kinder dimensions
	foreach group of newlist malpol fempol allpol men women {
		foreach scale of varlist dk_* d_* {   		// prepro*
			capture drop l*_`group'_`scale'_us
			qui reg ln `scale' if tarshort=="`group'"
			qui lincom `scale' + _cons/5
			qui gen l_`group'_`scale'_us = r(estimate) 
			qui gen llb_`group'_`scale'_us = r(lb)  
			qui gen lub_`group'_`scale'_us = r(ub)  
			    gen lse_`group'_`scale'_us = r(se)
		}
	}

	* Step 4: Create standardized score on trait scale. Standardization is relative to the trait percentages over all groups. 
	drop if trait==""
	rename (l_malpol_us l_fempol_us l_allpol_us l_women_us l_men_us) (l_us_malpol l_us_fempol l_us_allpol l_us_women l_us_men)
	reshape long l_us_ , i(trait) j(group) string
	qui sum l_us_
	global meantrait = r(mean)
	global sdtrait = r(sd)
	reshape wide l_us_ , i(trait) j(group) string
	rename (l_us_malpol l_us_fempol l_us_allpol l_us_women l_us_men) (l_malpol_us l_fempol_us l_allpol_us l_women_us l_men_us) 
		
	foreach scale of varlist dk_* d_* {  // prepro* 
		foreach group of newlist fempol malpol allpol men women {
			//di "l_`group'_`scale'_us_std"
			gen   l_`group'_`scale'_us_std = (  l_`group'_`scale'_us - $meantrait) / $sdtrait
			gen llb_`group'_`scale'_us_std = (llb_`group'_`scale'_us - $meantrait) / $sdtrait
			gen lub_`group'_`scale'_us_std = (lub_`group'_`scale'_us - $meantrait) / $sdtrait
			gen lse_`group'_`scale'_us_std = (lse_`group'_`scale'_us             ) / $sdtrait
			}
	}

	* Minimize scale dataset and reshape
	keep l_* llb_* lub_* lse_*
	drop if _n>1
	gen constant = 1
	
	foreach var of varlist *_std {
		local tempname = regexr("`var'","_std","") 
		local tempname = "std_" + "`tempname'"
		rename `var' `tempname'
	}
	foreach var of varlist *_us {
		local tempname = regexr("`var'","_us","") 
		rename `var' `tempname'
	}
	reshape long l_malpol_ llb_malpol_ lub_malpol_ lse_malpol_ l_fempol_ llb_fempol_ lub_fempol_ lse_fempol_ l_allpol_ llb_allpol_ lub_allpol_ lse_allpol_ l_men_ llb_men_ lub_men_ lse_men_ l_women_ llb_women_ lub_women_ lse_women_ std_l_fempol_ std_llb_fempol_ std_lub_fempol_ std_lse_fempol_ std_l_malpol_ std_llb_malpol_ std_lub_malpol_ std_lse_malpol_ std_l_allpol_ std_llb_allpol_ std_lub_allpol_ std_lse_allpol_ std_l_men_ std_llb_men_ std_lub_men_ std_lse_men_ std_l_women_ std_llb_women_ std_lub_women_ std_lse_women_, i(constant) j(trait) string
	drop constant *_allpol *_fempol *_malpol *_men *_women 
	
	foreach var of varlist *_ {
		local tempname = "`var'" + "us" 
		rename `var' `tempname'
	}
	foreach var of varlist std_* {
		local tempname = regexr("`var'","std_","") 
		local tempname = "`tempname'" + "_std"
		rename `var' `tempname'
	}

	* Store
	format l* %3.2f
	save "listscalescores_US.dta", replace
	//save "Subgroup data\listscalescores_US.dta", replace
		
restore






